import os,django,time
from loguru import logger
import tkinter as tk
from tkinter import messagebox
os.environ.setdefault('DJANGO_SETTINGS_MODULE','application.settings')
django.setup()
from apps.data_analy.models import DataAnaly

window = tk.Tk()
window.title("德州哈特瑞姆心血管病医院")
if __name__ == '__main__':
    label = tk.Label(window,text="智能接口监控平台")
    label.pack()
    button = tk.Button(window,text="单击")
    button.pack()
    # 最大化
    window.state("zoomed")
    # 全屏
    # window.attributes('-fullscreen',True)
    window.mainloop()
    # 循环监控异常数据
    while True:
        # HIS通讯异常
        data_hiserror = DataAnaly.objects.filter(except_type=1,cancel_type="0").order_by("-id")
        if data_hiserror.count()>0:
            query_answer = messagebox.askquestion("HIS通讯错误","HIS通讯出现错误，请联系HIS工程师解决")
            if str(query_answer)=="yes":
                DataAnaly.objects.filter(except_type=1,cancel_type="0").update(cancel_type="1")
            else:
                DataAnaly.objects.filter(except_type=1,cancel_type="0").update(cancel_type="3")

        # FTP配置错误
        data_ftperror = DataAnaly.objects.filter(except_type=2, cancel_type="0").order_by("-id")
        if data_ftperror.count() > 0:
            query_answer = messagebox.askquestion("FTP配置错误", "FTP配置错误，请联系摆药机工程师解决")
            if str(query_answer) == "yes":
                DataAnaly.objects.filter(except_type=2, cancel_type="0").update(cancel_type="2")
            else:
                DataAnaly.objects.filter(except_type=2,cancel_type="0").update(cancel_type="3")

            time.sleep(20)